package com.jack.payment.util.common;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class ImageUtils {
    private Logger log = LoggerFactory.getLogger(this.getClass());


    public static void main(String[] args) {
        imagesCorp();
    }

    public static void imagesCorp() {
        try {
            BufferedImage sourceImage = ImageIO.read(new File("C:\\Users\\PC\\Desktop\\h5_template\\mobw\\3\\3.jpg"));
            // 设置裁剪区域的起始坐标和宽高
            int x = 0;
            int y = 0;
            int width = 693;
            int height = 380;

            // 创建一个新的BufferedImage对象，用于存储裁剪后的图像
            BufferedImage croppedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

            // 循环遍历裁剪区域，并将待裁剪的像素复制到新的图像中
            for (int i = 0; i < width; i++) {
                for (int j = 0; j < height; j++) {
                    int rgb = sourceImage.getRGB(i + x, j + y);
                    croppedImage.setRGB(i, j, rgb);
                }
            }

            // 保存裁剪后的图像
            ImageIO.write(croppedImage, "jpg", new File("C:\\Users\\PC\\Desktop\\3.jpg"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}